#pragma once

#include "Timer.h"

namespace sol9
{
namespace util
{

	class FrameCounter
	{
	private:
		Timer m_Timer;
		u32 m_nRefreshRate;
		u32 m_nFrame;
		u32 m_nFPS;

	public:
		FrameCounter(u32 rateMs = 1000)
			: m_Timer(true), m_nRefreshRate(rateMs)
			, m_nFrame(0), m_nFPS(0) {}

		void countFrame()
		{
			++m_nFrame;
			_calculateFrame();
		}

		u32 getFPS() const
		{
			return m_nFPS;
		}

	private:
		void _calculateFrame()
		{
			if (m_Timer >= m_nRefreshRate)
			{
				m_nFPS = m_nFrame;
				m_nFrame = 0;
				m_Timer -= m_nRefreshRate;

			}
		}
	};

} // namespace util
} // namespace sol9